package player.model;

import java.io.Serializable;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;

/**
 * Model tabele za playlistu
 * @author Andrej
 */
public class PlaylistModel implements TableModel, Serializable
{

    private Object mat[][];
    private Track tracks[];
    private Object column[];

    /**
     * Konstruktor
     * @param mat matrica objekata
     * @param column niz headera tabele
     * @param tracks niz odgovarajucih trackova
     */
    public PlaylistModel(Object mat[][], Object column[], Object tracks[])
    {
        this.mat = mat;
        this.column = column;
        this.tracks = new Track[tracks.length];
        for (int i = 0; i < tracks.length; i++)
        {
            this.tracks[i] = (Track) tracks[i];
        }
    }

    /**
     * Vraca index tracka
     * @param t track
     * @return index datog tracka
     */
    public int getTrackIndex(Track t)
    {
        for (int i = 0; i < tracks.length; i++)
        {
            if (t.equals(tracks[i]))
            {
                return i;
            }
        }
        return -1;
    }

    /**
     * Vraca track na datoj poziciji
     * @param rowIndex pozicija reda
     * @return track na poziciji 
     */
    public Track getTrackAt(int rowIndex)
    {
        return tracks[rowIndex];
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex)
    {
    }

    @Override
    public void removeTableModelListener(TableModelListener l)
    {
        // TODO Auto-generated method stub
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex)
    {

        return false;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex)
    {
        return mat[rowIndex][columnIndex];
    }

    

    @Override
    public int getRowCount()
    {
        return mat.length;
    }

    @Override
    public String getColumnName(int columnIndex)
    {
        return column[columnIndex].toString();
    }

    @Override
    public int getColumnCount()
    {
        return mat[0].length;
    }

    @Override
    public Class<?> getColumnClass(int columnIndex)
    {
        return String.class;
    }

    @Override
    public void addTableModelListener(TableModelListener l)
    {
        // TODO Auto-generated method stub
    }
}
